package com.example.androidframework

import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import com.example.androidframework.impl.ActivityLifecycleCallback
import com.martin.lib_base.base.BaseApplication
import com.martin.lib_base.constant.ConstantKey
import com.tencent.mmkv.MMKV
import com.xuexiang.xui.widget.toast.XToast

class MyApplication : BaseApplication() {

    companion object {
        @SuppressLint("StaticFieldLeak")
        var MyApp: MyApplication? = null

        fun instance() = MyApp

        // 全局context
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
    }

    override fun onCreate() {
        super.onCreate()

        MyApp = this

        // 全局context
        context = applicationContext

        registerActivityLifecycleCallbacks(ActivityLifecycleCallback())

        if (MMKV.defaultMMKV().getBoolean(ConstantKey.FIRST_PRIVACY, false)) {
            initData()
        }
    }

    fun initData() {
        //设置为中间展示Toast
        XToast.Config.get().setGravity(Gravity.CENTER)
    }
}